﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _09_1对多
{
    public class CommentConfig : IEntityTypeConfiguration<Comment>
    {
        public void Configure(EntityTypeBuilder<Comment> builder)
        {
            builder.ToTable("T_Comments");
            builder.Property(e => e.Message).IsUnicode().IsRequired();
            // 多的写，一的地方就不用写
            // builder.HasOne(e => e.Article1).WithMany(a => a.comments).HasForeignKey(a=>a.Article2).IsRequired(); //不要用冲突太多

            builder.HasOne(e => e.Article1).WithMany(a => a.comments).IsRequired();
        }
    }
}
